package com.sk.cardeal.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.cardeal.R;
import com.sk.cardeal.entity.Series;
import com.sk.cardeal.utils.HttpAddress;

import java.util.List;

/**
 * Created by sk on 2018/1/11.
 */

public class SeriesAdapter extends BaseQuickAdapter<Series,BaseViewHolder> {

    private String url;

    public SeriesAdapter(int layoutResId, @Nullable List<Series> data,String url) {
        super(layoutResId, data);
        this.url = url;
    }

    @Override
    protected void convert(BaseViewHolder helper, Series item) {
        helper.setText(R.id.tv_name,item.getText())
                .setText(R.id.catalog,item.getInitials());

        if(helper.getAdapterPosition() != 0){
            if(item.getInitials().equals(mData.get(helper.getAdapterPosition()-1).getInitials())){
                helper.setGone(R.id.catalog,false);
            }else {
                helper.setGone(R.id.catalog,true);
            }
        }else {
            helper.setGone(R.id.catalog,true);
        }
    }

    /**
     * 根据分类的首字母的Char ascii值获取其第一次出现该首字母的位置
     */
    public int getPositionForSection(String s) {
        for (int i = 0; i < mData.size(); i++) {
            String num = mData.get(i).getInitials();
            if(s.equals(num)){
                return i;
            }
        }

        return -1;
    }
}
